package com.docMan.service.impl;



import java.sql.Date;
import java.sql.Timestamp;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.docMan.dao.BaseDao;
import com.docMan.dao.pojo.DocDisc;
import com.docMan.dao.pojo.DocFile;
import com.docMan.dao.pojo.Tcunit;
import com.docMan.service.DocDiscService;
import com.docMan.service.TcunitService;
import com.docMan.utils.FinalConfig;

@Service("docDiscService")
public class DocDiscServiceImpl extends BaseServiceImpl<DocDisc> implements DocDiscService {
	private TcunitService tcunitService;
	private HttpSession session;
	@Autowired
	public void setSession(HttpSession session) {
		this.session = session;
	}

	@Resource
	public void setTcunitService(TcunitService tcunitService) {
		this.tcunitService = tcunitService;
	}

	@Resource
	@Override
	public void setDao(BaseDao<DocDisc> dao) {
		// TODO Auto-generated method stub
		super.setDao(dao);
	}

	@Override
	public String saveOrUpdateDocDisc(DocDisc docDisc) {
		if(!(boolean)session.getAttribute(FinalConfig.SESSION_ADMIN)){
			putFalse();
			putMessage("你不是管理员");
			return getMap();
		}
		if(docDisc.getId()==null||docDisc.getId()<=0){
			docDisc.setHumanId((Integer)session.getAttribute(FinalConfig.SESSION_HUMANID));
			docDisc.setFileCount(0);
			docDisc.setLarge(0.0);
			docDisc.setHumanName((String)session.getAttribute(FinalConfig.SESSION_HUMANNAME));
			docDisc.setDirectoryCount(0);
			docDisc.setCreateTime(new Timestamp(System.currentTimeMillis()));
		}
		saveOrUpdate(docDisc);
		put("disk", docDisc);
		putSuccess();
		return getMap();
	}

	@Override
	public String getDiscAttr(int diskId) {
		DocDisc docDisc=getById(diskId);
		Tcunit tcunit=tcunitService.getById(docDisc.getUnitId());
		put("docDisk", docDisc);
		put("unit", tcunit);
		putSuccess();
		return getMap();
	}
	
}
